package com.akuhome.resource.controller;

import com.akuhome.resource.dto.report.MonthTrainInfo;
import com.akuhome.resource.service.ReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

@RestController
@RequestMapping("/report")
public class ReportController {
    @Autowired
    ReportService reportService;

    @GetMapping("/month")
    public Object findAllDepStaByDateMonth(Date date){
        return reportService.findAllDepStaByDateMonth(date);
    }
    @GetMapping("/month/{id}")
    public Object findAllTrainStaByDateMonth(@PathVariable Integer id,String part){
        MonthTrainInfo monthTrainInfo = new MonthTrainInfo();
        //通过monthReportId获取月份
        monthTrainInfo.setDate(reportService.findDateByMonthReportId(id));
       if(part == null || part.startsWith("所有部门")){
           //获取所有部门的培训统计
            monthTrainInfo.setStatisticList(reportService.findAllTrainStatisticByMonthReportId(id));
       }else{
           //获取指定部门的培训统计
           monthTrainInfo.setStatisticList(reportService.findAllTrainStatisticByPartAndMonthReportId(part,id));
       }
       return monthTrainInfo;
    }

    @GetMapping("/year")
    public Object findAllMonStaByDateYear(Date date){
        return reportService.findAllMonStaByDateYear(date);
    }

    @GetMapping("/year/{id}")
    public Object findYearTrainInfo(@PathVariable Integer id,String part){
        return reportService.findYearTrainInfoByPartAndYearReportId(part,id);
    }
}
